﻿
#region Usings
using FasterWPF;
using FasterWPFDemo.UserControls;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
#endregion

namespace FasterWPFDemo
{
    public class TabItem03 : UserControl, IUserControlGuid
    {
        private string _userCtlGuid = null;

        public string UserControlGuid
        {
            get
            {
                return _userCtlGuid;
            }

            set
            {
                _userCtlGuid = value;
            }
        }

        public TabItem03()
        {
            //InitializeComponent(); XAML removed. Initialize via code-behind.

            this.Initialize(ContainerType.DockPanel);
            this.SetCompositeDockPanelLastChildFill<UserControl>(true);

            this.Width = 450D;
            this.Height = 350D;

            this.BeginSettings<UserControl>().Set<Button, UserControl>(1, 1, "Foreground", Brushes.Red)
                 .SetSelectorClass<UserControl>(1, 0, "tabLabel")
                 .SetSelectorClass<UserControl>(1, 1, "bold", "tabItem3")
                 .SetSelectorClass<UserControl>(1, 2, "italic", "bold", "tabItem3")
                 .SetItemBorderColorAndThickness<UserControl>(Brushes.Gray, new Thickness(3)).EndSettings();
        }

        public void LoadUserControl()
        { 
            //TAB ITEM 3 - RICH TEXTBOX EXAMPLE

            RichTextBox rtb = new RichTextBox();
            rtb.InitializeForScrollViewerSupport(500D, 500D, 140D);  //TextBox is NOT an IParent but it is an IScrollViewerStrategy.
            ScrollViewerStyle.ApplyToScrollViewer<RichTextBox>(rtb, "MistyRose", "White", "Red");
            rtb.HorizontalScrollBarVisibility = ScrollBarVisibility.Visible;
            
            FlowDocument flowDoc = new FlowDocument();
            rtb.Document = flowDoc
                 .AddParagraph("Arial", FontStyles.Normal, 12, Brushes.Black, FontWeights.Bold, new Run("Hello World\n\n\n\n"))
                 .AddParagraph("Arial", FontStyles.Normal, 12, Brushes.Red, FontWeights.Normal, "Here is longer text to force the vertical scrollbar to display.\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\nMake this a long run-on sentence just to make the scrollbar display.");

            Button b99 = new Button();
            b99.Initialize(155D, 27D, ContainerType.ContentControlPanel);
            b99.BeginComposite<Button>().AddText<Button>(0,0,  "Bold Selected Text").EndComposite<Button, ButtonArgs>(null);
            b99.SubscribeEventOnParent<Button, MouseButtonEventArgs>("PreviewMouseDown", (ve => { rtb.Selection.ApplyPropertyValue(TextElement.FontWeightProperty, FontWeights.Bold); }));

            Button b100 = new Button();
            b100.Initialize(305D, 27D, ContainerType.ContentControlPanel);
            b100.BeginComposite<Button>().AddText<Button>(0, 0, "Apply Verdana to Selected Text").EndComposite<Button, ButtonArgs>(null);
            b100.SubscribeEventOnParent<Button, MouseButtonEventArgs>("PreviewMouseDown", (ve => { rtb.Selection.ApplyPropertyValue(TextElement.FontFamilyProperty, new FontFamily("Verdana")); })); 

            this.BeginComposite<UserControl>(_userCtlGuid)
                .AddLabel<UserControl>(1, 0, "Tab Item 3 -  Rich Text Example", Brushes.Red)
                .AddExisting<Button, UserControl>(1, 1, b99)
                .AddExisting<Button, UserControl>(1, 2, b100)  
                .AddExisting<RichTextBox, UserControl>(1, 3, rtb)
                .AddFlatButton<UserControl>(1, 4, 120D, 120D,
                "Remove this\n UserControl!", Brushes.GhostWhite, new Thickness(2), Brushes.Red, new CornerRadius(0), new Thickness(2), new Thickness(3), Brushes.Orange,
                (o, ev) =>
                {

                    //Retrieve Action from Global Store on Application object
                    GlobalStoreService.GetFromGlobalStore<Action<object, RoutedEventArgs>>(GlobalStoreService.TabControlGuids.Three, "TabItem3RemoveUserControl")(o, (RoutedEventArgs)ev);

                }).EndComposite<UserControl, UserControlArgs>(null);
        }
    }
}
